var findContentChildren = function(g, s) {
    g = g.sort((a,b)=> a-b);
    s = s.sort((a,b) => a-b);
    const n = g.length; const m = s.length;
    let num = 0;
    if(g[0] > s[m-1]) return num;
    let  j = 0;
    for(let i = 0; i < Math.min(m,n); i++) {
        // while(g[i]>s[j] && j<m) {
        //     j++;
        // }
        if(g[i]<=s[j]) {
            ++num;
        }
        j++;
    }
    return num;
  };
  var findContentChildren = function(g, s) {
    g = g.sort((a, b) => a - b)
    s = s.sort((a, b) => a - b)
    let result = 0
    let index = s.length - 1
    for(let i = g.length - 1; i >= 0; i--) {
        if(index >= 0 && s[index] >= g[i]) {
            result++
            index--
        }
    } 
    return result
};
  console.log(findContentChildren([1,2,3],[1,1]))
  console.log(findContentChildren([1,2],[1,2,3]))
  console.log(findContentChildren([1,2],[1,2]))